package hu.mapro.gwtui.client.login;

import com.google.gwt.user.client.ui.HasVisibility;

import hu.mapro.gwtui.client.Action;
import hu.mapro.gwtui.client.Visibility;

public class LoginUtils {
	
	public static Visibility whenLoggedIn(final LoginService loginService) {
		Visibility whenLoggedIn = new Visibility() {
			@Override
			public boolean isVisible() {
				return loginService.isLoggedIn();
			}
			
			@Override
			public void addChangeHandler(Action action) {
				loginService.addChangeHandler(action);
			}

			@Override
			public void removeChangeHandler(Action action) {
				loginService.removeChangeHandler(action);
			}
		};		
		return whenLoggedIn;
	}

	public static Visibility whenLoggedOut(final LoginService loginService) {
		Visibility whenLoggedOut = new Visibility() {
			@Override
			public boolean isVisible() {
				return !loginService.isLoggedIn();
			}
			
			@Override
			public void addChangeHandler(Action action) {
				loginService.addChangeHandler(action);
			}

			@Override
			public void removeChangeHandler(Action action) {
				loginService.removeChangeHandler(action);
			}
		};
		return whenLoggedOut;
	}

}
